'''
    语法：{key：value，key1，value1，，，}
    字典：
        key，value   可以是任意类型  但是一般我们的key指定的是字符串
        字典的key不能重复
        没有长度   没有索引
'''
if __name__ == '__main__':
    # 定义袁少侠的信息
    laoyuan = {'name':'袁少侠','sex':'男','age':18,'loves':['媳妇','闺女']}

    # 定义一个老师的信息

    teacher = {'name':'laoliu','classes':[['a', 'b', 'c'], ['q', 'w', 'e'], ['u', 'i', 'o']]}

    # 分类列表信息
    fenleilist = {'code':200,'message':'获取成功','data':[
        {'id':1,'name':'鞋子'},
        {'id':2,'name':'帽子'},
        {'id':3,'name':'电脑'}
    ]}
    # 增
    laoyuan['shengao'] = 175
    print(laoyuan)
    # 删
    del laoyuan['sex']
    print(laoyuan)

    dell = laoyuan.pop('loves')
    print(dell)
    print(laoyuan)


    # 查
    print(laoyuan['name'])
    # 改  如key不存在  则为添加
    laoyuan['loves'] = 'money'
    print(laoyuan)
    print('-------------------------------------------------------')
    teacher['name'] = 'laozhang'
    print(teacher)
    # 通过key获取value
    print(fenleilist['data'])
    print(fenleilist.get('data'))  # get   key不存在 正常执行且返回None

  # fenleilist = {'code':200,'message':'获取成功','data':[
  #       {'id':1,'name':'鞋子'},
  #       {'id':2,'name':'帽子'},
  #       {'id':3,'name':'电脑'}
    print(fenleilist['data'][2]['name'])

    # 字典的遍历  字典本身不支持循环  需要先转换为列表 再循环
    print(fenleilist.keys)
    print(type(fenleilist))
    for p in fenleilist.keys():
        print(p)
        print(fenleilist[p])
    print('--------------------------------------------')
    alist = fenleilist.items()
    for i in alist:
        print(i)
    for k,v in alist:
        print(k,v)







